<?php
/**
 * User: bim bip
 * Date: 7/28/11
 * Time: 10:08 PM
 */
class Contact extends CI_Controller{
    function __construct(){
        parent::__construct();
    }

    function index(){
        $data['site_message'] = '';
        if(!$this->input->post('send')){
            $this->load->model('m_hitcounter');
            $data['hitCounter'] = $this->m_hitcounter->hitCounter();
            $data['online'] = $this->m_hitcounter->online();
            $this->load->view('contacts/v_contacts',$data);
        }else{
            //check input
            if($this->input->post('name')
               && $this->input->post('email')
               && $this->input->post('message') != ''){ //if have full input
                //add message
                $this->load->model('site/messagemodel');
                $mess = new MessageModel();
                $mess->_email = $this->input->post('email');
                $mess->_message = $this->input->post('message');
                date_default_timezone_set('Asia/Ho_Chi_Minh'); //GMT+7
                $mess->_time = date('Y-m-d H:i:s');
                $mess->_name = $this->input->post('name');
                
                $mess->addNew();
                $data['site_message'] = 'Cám ơn bạn đã gửi tin nhắn cho chúng tôi. Chúng tôi sẽ ghi nhận!';
            }
            $this->load->model('m_hitcounter');
            $data['hitCounter'] = $this->m_hitcounter->hitCounter();
            $data['online'] = $this->m_hitcounter->online();
            $this->load->view('contacts/v_contacts',$data);
        }
    }
}
